[ASAN] tests: Cleanup all current remaining leaks
authorColin Walters <walters@verbum.org>
Fri, 2 Dec 2016 18:45:04 +0000 (13:45 -0500)
committerAtomic Bot <atomic-devel@projectatomic.io>
Mon, 5 Dec 2016 15:20:56 +0000 (15:20 +0000)
We now run fully through ASAN here.

Closes: #609
Approved by: jlebon

tests/test-bsdiff.c
tests/test-lzma.c
tests/test-mutable-tree.c
tests/test-ot-opt-utils.c
tests/test-ot-tool-util.c
tests/test-ot-unix-utils.c
tests/test-varint.c

index 5c5eb1049a48747e1316c1255bc92477ef6d14e0..24772a1e1e864ab20bbd56bc8c90f44c61c81b2e 100644 (file)
@@ -89,7 +89,9 @@ test_bsdiff (void)
   g_output_stream_close (out, NULL, NULL);
 
   /* Now generate NEW_GENERATED from OLD and OUT.  */
-  in = g_memory_input_stream_new_from_bytes (g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (out)));
+  { g_autoptr(GBytes) bytes = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (out));
+    in = g_memory_input_stream_new_from_bytes (bytes);
+  }
   bspatch_stream.read = bzpatch_read;
   bspatch_stream.opaque = in;
 
index 8d37d47f48cb3fc38a92a1edc14e5b8112762794..1f7d25597c9329551e96c957148561f971672a6e 100644 (file)
@@ -32,7 +32,7 @@
 static void
 helper_test_compress_decompress (const guint8 *data, gssize data_size)
 {
-  GError *error = NULL;
+  g_autoptr(GError) error = NULL;
   g_autoptr(GOutputStream) out_compress = g_memory_output_stream_new_resizable ();
   g_autoptr(GOutputStream) out_decompress = NULL;
   g_autoptr(GInputStream) in_compress = g_memory_input_stream_new_from_data (data, data_size, NULL);
@@ -55,9 +55,10 @@ helper_test_compress_decompress (const guint8 *data, gssize data_size)
   {
     gssize n_bytes_written;
     g_autoptr(GInputStream) convin = NULL;
-  g_autoptr(GConverter) decompressor = (GConverter*)_ostree_lzma_decompressor_new ();
+    g_autoptr(GConverter) decompressor = (GConverter*)_ostree_lzma_decompressor_new ();
+    g_autoptr(GBytes) bytes = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (out_compress));
 
-    in_decompress = g_memory_input_stream_new_from_bytes (g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (out_compress)));
+    in_decompress = g_memory_input_stream_new_from_bytes (bytes);
     convin = g_converter_input_stream_new ((GInputStream*) in_decompress, decompressor);
     n_bytes_written = g_output_stream_splice (out_decompress, convin,
                                               G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET | G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE,
index b357f691756c7838904180ee90fba357f24d0f99..9df36ac626a5ef31ab7e70b2bbcca4a2b622e886 100644 (file)
@@ -84,7 +84,7 @@ test_ensure_parent_dirs (void)
   glnx_unref_object OstreeMutableTree *tree = ostree_mutable_tree_new ();
   glnx_unref_object OstreeMutableTree *parent = NULL;
   g_autoptr(GPtrArray) split_path = NULL;
-  GError *error = NULL;
+  g_autoptr(GError) error = NULL;
   const char *pathname = "/foo/bar/baz";
   const char *checksum = "01234567890123456789012345678901";
   g_autofree char *source_checksum = NULL;
@@ -103,6 +103,7 @@ test_ensure_parent_dirs (void)
 
   g_assert_false (ostree_mutable_tree_lookup (tree, "bar", &source_checksum2,
                                               &source_subdir2, &error));
+  g_clear_error (&error);
 }
 
 static void
@@ -110,7 +111,7 @@ test_ensure_dir (void)
 {
   glnx_unref_object OstreeMutableTree *tree = ostree_mutable_tree_new ();
   glnx_unref_object OstreeMutableTree *parent = NULL;
-  GError *error = NULL;
+  g_autoptr(GError) error = NULL;
   const char *dirname = "foo";
   const char *filename = "bar";
   const char *checksum = "01234567890123456789012345678901";
@@ -122,13 +123,14 @@ test_ensure_dir (void)
 
   g_assert (ostree_mutable_tree_replace_file (tree, filename, checksum, &error));
   g_assert_false (ostree_mutable_tree_ensure_dir (tree, filename, &parent, &error));
+  g_clear_error (&error);
 }
 
 static void
 test_replace_file (void)
 {
   glnx_unref_object OstreeMutableTree *tree = ostree_mutable_tree_new ();
-  GError *error = NULL;
+  g_autoptr(GError) error = NULL;
   const char *filename = "bar";
   const char *checksum = "01234567890123456789012345678901";
   const char *checksum2 = "ABCDEF01234567890123456789012345";
@@ -157,7 +159,7 @@ test_contents_checksum (void)
   const char *subdir_checksum = "ABCD0123456789012345678901234567";
   glnx_unref_object OstreeMutableTree *tree = ostree_mutable_tree_new ();
   glnx_unref_object OstreeMutableTree *subdir = NULL;
-  GError *error = NULL;
+  g_autoptr(GError) error = NULL;
   g_assert_null (ostree_mutable_tree_get_contents_checksum (tree));
 
   ostree_mutable_tree_set_contents_checksum (tree, checksum);
index 1a7230b312c2816e07a58d884ce6d99a15a49203..77ecdf30233ade49b36eb75380577c5a15c8f8cc 100644 (file)
@@ -40,19 +40,19 @@ util_usage_error_printerr (const gchar *string)
 static void
 test_ot_util_usage_error (void)
 {
-  GError *error = NULL;
-  GOptionContext *context = g_option_context_new ("[TEST]");
+  g_autoptr(GError) error = NULL;
+  g_autoptr(GOptionContext) context = g_option_context_new ("[TEST]");
   GPrintFunc old_printerr = g_set_printerr_handler (util_usage_error_printerr);
 
   ot_util_usage_error (context, "find_me", &error);
 
   g_assert_nonnull (strstr (printerr_str->str, "[TEST]"));
   g_assert_nonnull (strstr (error->message, "find_me"));
+  g_clear_error (&error);
 
   g_set_printerr_handler (old_printerr);
   g_string_free (printerr_str, TRUE);
   printerr_str = NULL;
-  g_option_context_free (context);
 }
 
 int main (int argc, char **argv)
index e63a01852fc2cabe4a93a1a23582e2e7e4d3db53..13030fe449bfd4cfba53cf31a8057900f7710309 100644 (file)
@@ -43,7 +43,7 @@ ot_parse_keyvalue (const char  *keyvalue,
 static void
 test_ot_parse_boolean (void)
 {
-  GError *error = NULL;
+  g_autoptr(GError) error = NULL;
   gboolean out = FALSE;
   g_assert_true (ot_parse_boolean ("yes", &out, &error));
   g_assert_true (out);
@@ -70,15 +70,17 @@ test_ot_parse_boolean (void)
   out = TRUE;
   g_assert_true (ot_parse_boolean ("none", &out, &error));
   g_assert_false (out);
+  g_clear_error (&error);
 
   g_assert_false (ot_parse_boolean ("FOO", &out, &error));
   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED);
+  g_clear_error (&error);
 }
 
 static void
 test_ot_parse_keyvalue (void)
 {
-  GError *error = NULL;
+  g_autoptr(GError) error = NULL;
   char *keyvalue[] = {"foo=bar", "a=", "b=1231231"};
   char *key[] = {"foo", "a", "b"};
   char *value[] = {"bar", "", "1231231"};
@@ -104,6 +106,7 @@ test_ot_parse_keyvalue (void)
                                        &out_value,
                                        &error));
     g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED);
+    g_clear_error (&error);
   }
 }
 
index 6c77d2a2e44509881da6d64601220ec27066e64d..5eeab1d1066c29f7e67bcca2e3632c3c1b913377 100644 (file)
@@ -50,22 +50,29 @@ test_ot_util_path_split_validate (void)
 static void
 test_ot_util_filename_validate (void)
 {
-  GError *error = NULL;
+  g_autoptr(GError) error = NULL;
 
   /* Check for valid inputs.  */
   g_assert (ot_util_filename_validate ("valid", &error));
+  g_assert_no_error (error);
   g_assert (ot_util_filename_validate ("valid_file_name", &error));
+  g_assert_no_error (error);
   g_assert (ot_util_filename_validate ("file.name", &error));
+  g_assert_no_error (error);
   g_assert (ot_util_filename_validate ("foo..", &error));
+  g_assert_no_error (error);
   g_assert (ot_util_filename_validate ("..bar", &error));
+  g_assert_no_error (error);
   g_assert (ot_util_filename_validate ("baz:", &error));
+  g_assert_no_error (error);
 
   /* Check for invalid inputs.  */
   g_assert_false (ot_util_filename_validate ("not/valid/file/name", &error));
-  error = NULL;
+  g_clear_error (&error);
   g_assert_false (ot_util_filename_validate (".", &error));
-  error = NULL;
+  g_clear_error (&error);
   g_assert_false (ot_util_filename_validate ("..", &error));
+  g_clear_error (&error);
 }
 
 int main (int argc, char **argv)
index 76f85573c93624fe248dd5fe2d19a44864a9ba8a..062c47ef7933eae01e26a3570f197c839b0d889d 100644 (file)
@@ -27,7 +27,7 @@
 static void
 check_one_roundtrip (guint64    val)
 {
-  GString *buf = g_string_new (NULL);
+  g_autoptr(GString) buf = g_string_new (NULL);
   guint64 newval;
   gsize bytes_read;